package com.wind.stream;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Stream的使用：提取/组合
 *
 * @author Wind
 * @date 2021-06-09
 */
public class Test12Stream {
    public static void main(String[] args) {

        String[] arr1 = {"a", "b", "c", "d"};
        String[] arr2 = {"d", "e", "f", "g"};
        Stream<String> stream1 = Stream.of(arr1);
        Stream<String> stream2 = Stream.of(arr2);

        // concat：合并两个流，去重
        List<String> arr = Stream.concat(stream1, stream2).distinct().collect(Collectors.toList());
        arr.forEach(System.out::print);
        System.out.println();

        // limit：限制从流中获得前n个数据
        List<Integer> limit = Stream.iterate(1, t -> t + 2).limit(10).collect(Collectors.toList());
        limit.forEach(t -> System.out.print(t + ","));
        System.out.println();

        // skip：跳过前n个数据
        List<Integer> skip = Stream.iterate(1, t -> t + 2).skip(2).limit(5).collect(Collectors.toList());
        skip.forEach(t -> System.out.print(t + ",")); // 跳过了 1和3
    }
}
